package top.kiterunner.learning.concurrency_test;

/**
 * AdorynZhao in Tencent-UESTC.
 * Source Code Created on 2017/7/3.
 */
public class ThreadDemo1 implements Runnable {

    private int count = 0;

    // 没有synchronized，会出现问题
    // 可以认为，synchronzied是原子操作，不可分
    public synchronized void run() {
        count++;
        System.out.println(Thread.currentThread().getName() + " Count = " + count);
    }

    public static void main(String[] args) {
        ThreadDemo1 t1 = new ThreadDemo1();
        for(int i = 0; i < 5; i++) {
            new Thread(t1, "THREAD" + i).start();
        }
    }
}
